﻿#include "ChangeTicketDialog.h"
#include <Global_Class.h>
#include <orders.h>
#include <seats.h>///lude <trains.h>
#include <stations.h>
#include <QMessageBox>
#include <set>
#include <QDateEdit>
#include <QCalendarWidget>

//ChangeTicketDialog::ChangeTicketDialog(const orders& oldOrder, QWidget* parent)
//    : QDialog(parent), oldOrderRef(oldOrder) {
//    setWindowTitle("选择新车次、日期和座位");
//    QVBoxLayout* layout = new QVBoxLayout(this);
//    // 发站和到站
//    QString fromName, toName;
//    for (const auto& st : allData->stationsQueue) {
//        if (st.getStationId() == oldOrder.getStartStationId()) fromName = QString::fromStdString(st.getName());
//        if (st.getStationId() == oldOrder.getEndStationId()) toName = QString::fromStdString(st.getName());
//    }
//    fromLabel = new QLabel("发站: " + fromName, this);
//    toLabel = new QLabel("到站: " + toName, this);
//    layout->addWidget(fromLabel);
//    layout->addWidget(toLabel);
//    infoLabel = new QLabel("请选择新的车次、日期和座位：", this);
//    layout->addWidget(infoLabel);
//    // 票价显示标签
//    priceLabel = new QLabel("票价: --", this);
//    layout->addWidget(priceLabel);
//    trainCombo = new QComboBox(this);
//    layout->addWidget(trainCombo);
//    // 用QDateEdit+QCalendarWidget替换QComboBox日期选择
//    dateEdit = new QDateEdit(this);
//    dateEdit->setCalendarPopup(true);
//    QDate today = QDate::currentDate();
//    dateEdit->setDate(today);
//    dateEdit->setMinimumDate(today);
//    dateEdit->setMaximumDate(today.addDays(31));
//    layout->addWidget(dateEdit);
//    seatCombo = new QComboBox(this);
//    layout->addWidget(seatCombo);
//    btnConfirm = new QPushButton("确认改签", this);
//    layout->addWidget(btnConfirm);
//    loadTrains();
//    connect(trainCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ChangeTicketDialog::onTrainChanged);
//    connect(dateEdit, &QDateEdit::dateChanged, this, &ChangeTicketDialog::onDateChanged);
//    connect(seatCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ChangeTicketDialog::updatePriceLabel);
//    connect(btnConfirm, &QPushButton::clicked, this, &ChangeTicketDialog::onConfirmClicked);
//    setLayout(layout);
//}
//
void ChangeTicketDialog::loadTrains() {
    trainCombo->clear();
    if (!allData) {
        trainCombo->addItem("[数据未初始化]");
        seatCombo->clear();
        seatCombo->addItem("[数据未初始化]");
        return;
    }
    int defaultIndex = -1;
    int idx = 0;
    bool found = false;
    std::set<int> validTrainIds;
    // 1. 找到所有途经订单起止站且顺序正确的车次
    for (const auto& train : allData->trainQueue) {
        int trainId = train.getTrainId();
        int startOrder = -1, endOrder = -1;
        for (const auto& sch : allData->trainSchedules) {
            if (sch.getTrainId() == trainId) {
                if (sch.getStationId() == oldOrderRef.getStartStationId()) startOrder = sch.getStopOrder();
                if (sch.getStationId() == oldOrderRef.getEndStationId()) endOrder = sch.getStopOrder();
            }
        }
        if (startOrder != -1 && endOrder != -1 && startOrder < endOrder) {
            validTrainIds.insert(trainId);
        }
    }
    for (const auto& train : allData->trainQueue) {
        if (validTrainIds.count(train.getTrainId())) {
            trainCombo->addItem(QString::fromStdString(train.getTrainCode()), train.getTrainId());
            if (train.getTrainId() == oldOrderRef.getTrainId()) {
                defaultIndex = idx;
            }
            ++idx;
            found = true;
        }
    }
    if (!found) {
        trainCombo->addItem("[无可用车次]");
        seatCombo->clear();
        seatCombo->addItem("[无可用座位]");
        return;
    }
    if (trainCombo->count() > 0) {
        if (defaultIndex >= 0) {
            trainCombo->setCurrentIndex(defaultIndex);
        } else {
            trainCombo->setCurrentIndex(0);
        }
        loadSeats(trainCombo->currentData().toInt(), dateEdit->date().toString("yyyy-MM-dd").toStdString());
    } else {
        seatCombo->clear();
        seatCombo->addItem("[无可用座位]");
    }
}

void ChangeTicketDialog::onTrainChanged(int idx) {
    if (idx < 0) return;
    int trainId = trainCombo->itemData(idx).toInt();
    loadSeats(trainId, dateEdit->date().toString("yyyy-MM-dd").toStdString());
    updatePriceLabel();
}

void ChangeTicketDialog::onDateChanged(const QDate& date) {
    int trainId = trainCombo->currentData().toInt();
    if (trainId == -1) return;
    loadSeats(trainId, date.toString("yyyy-MM-dd").toStdString());
    updatePriceLabel();
}
//
//void ChangeTicketDialog::loadSeats(int trainId, const std::string& date) {
//    seatCombo->clear();
//    if (!allData) {
//        seatCombo->addItem("[数据未初始化]");
//        return;
//    }
//    bool found = false;
//    for (const auto& seat : allData->seatsQueue) {
//        if (seat.getTrainId() == trainId) {
//            // seatOccupy机制判断区间可用
//            bool available = allData->IsSeatAvailable(date, trainId, seat.getSeatId(), oldOrderRef.getStartStationId(), oldOrderRef.getEndStationId());
//            if (available) {
//                seatCombo->addItem(QString::fromStdString(seat.getSeatNo()), seat.getSeatId());
//                found = true;
//            }
//        }
//    }
//    // 默认选中原订单座位（如果可用），否则第一个可用座位
//    int defaultSeatIdx = -1;
//    for (int i = 0; i < seatCombo->count(); ++i) {
//        if (seatCombo->itemData(i).toInt() == oldOrderRef.getSeatId()) {
//            defaultSeatIdx = i;
//            break;
//        }
//    }
//    if (seatCombo->count() > 0) {
//        if (defaultSeatIdx >= 0) {
//            seatCombo->setCurrentIndex(defaultSeatIdx);
//        } else {
//            seatCombo->setCurrentIndex(0);
//        }
//    } else {
//        seatCombo->addItem("[无可用座位]");
//    }
//}
//
//void ChangeTicketDialog::updatePriceLabel() {
//    if (trainCombo->currentIndex() < 0 || seatCombo->currentIndex() < 0) {
//        priceLabel->setText("票价: --");
//        return;
//    }
//    int trainId = trainCombo->currentData().toInt();
//    int seatId = seatCombo->currentData().toInt();
//    std::string seatType;
//    for (const auto& seat : allData->seatsQueue) {
//        if (seat.getSeatId() == seatId && seat.getTrainId() == trainId) {
//            seatType = seat.getSeatType();
//            break;
//        }
//    }
//    double price = AllData::CalculateTicketPrice(
//        oldOrderRef.getStartStationId(), oldOrderRef.getEndStationId(), seatType, allData->stationsQueue);
//    if (price < 0) priceLabel->setText("票价: --");
//    else priceLabel->setText(QString("票价: %1 元").arg(QString::number(price, 'f', 2)));
//}

void ChangeTicketDialog::onConfirmClicked() {
    if (trainCombo->currentIndex() < 0 || seatCombo->currentIndex() < 0) {
        QMessageBox::warning(this, "改签失败", "请选择新车次、日期和座位");
        return;
    }
    newTrainId = trainCombo->currentData().toInt();
    newSeatId = seatCombo->currentData().toInt();
    newDate = dateEdit->date().toString("yyyy-MM-dd").toStdString();
    if (newTrainId == oldOrderRef.getTrainId() && newSeatId == oldOrderRef.getSeatId() && newDate == oldOrderRef.getTravelDate()) {
        QMessageBox::warning(this, "改签失败", "新车次、日期和座位不能与原订单相同");
        return;
    }
    // 1. 彻底删除所有与旧订单完全匹配的座位占用记录
    for (auto it = allData->seatOccupyQueue.begin(); it != allData->seatOccupyQueue.end(); ) {
        if (
            it->getDate() == oldOrderRef.getTravelDate() &&
            it->getTrainId() == oldOrderRef.getTrainId() &&
            it->getSeatId() == oldOrderRef.getSeatId() &&
            it->getStartStationId() == oldOrderRef.getStartStationId() &&
            it->getEndStationId() == oldOrderRef.getEndStationId() &&
            it->getOrderId() == oldOrderRef.getOrderId()
        ) {
            it = allData->seatOccupyQueue.erase(it);
        } else {
            ++it;
        }
    }
    // 2. 占用新座位
    std::string seatNo;
    for (const auto& seat : allData->seatsQueue) {
        if (seat.getSeatId() == newSeatId && seat.getTrainId() == newTrainId) {
            seatNo = seat.getSeatNo();
            break;
        }
    }
    if (seatNo.empty()) {
        seatNo = std::to_string(newSeatId);
    }
    SeatOccupy newOcc(newDate, newTrainId, newSeatId, seatNo, oldOrderRef.getStartStationId(), oldOrderRef.getEndStationId(), oldOrderRef.getOrderId());
    allData->seatOccupyQueue.push_back(newOcc);
    // 调试输出，确认新记录内容
    for (const auto& so : allData->seatOccupyQueue) {
        printf("SeatOccupy: %s, %d, %d, %s, %d, %d, %d\n ",
            so.getDate().c_str(), so.getTrainId(), so.getSeatId(), so.getSeatNo().c_str(),
            so.getStartStationId(), so.getEndStationId(), so.getOrderId());
    }
    // 3. 持久化到文件
    allData->SeatOccupy_WriteToFile("seat_occupy.txt");
    success = true;
    accept();
}


//这下面是修改UI的部分----------------------------------------------------------------------------------

ChangeTicketDialog::ChangeTicketDialog(const orders& oldOrder, QWidget* parent)
    : QDialog(parent), oldOrderRef(oldOrder) {
    setWindowTitle("车票改签");
    setMinimumSize(500, 500); // 增加对话框高度
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

    // 设置字体
    QFont globalFont("Microsoft YaHei", 10);
    QFont titleFont("Microsoft YaHei", 11, QFont::Bold);
    setFont(globalFont);

    // 主布局
    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    mainLayout->setContentsMargins(20, 20, 20, 20);
    mainLayout->setSpacing(15);

    // === 标题区域 ===
    QLabel* titleLabel = new QLabel("车票改签", this);
    titleLabel->setFont(QFont("Microsoft YaHei", 14, QFont::Bold));
    titleLabel->setStyleSheet("color: #2c3e50; padding: 8px 0;");
    titleLabel->setAlignment(Qt::AlignCenter);
    mainLayout->addWidget(titleLabel);

    // === 原订单信息卡片 ===
    QFrame* orderInfoFrame = new QFrame(this);
    orderInfoFrame->setFrameStyle(QFrame::StyledPanel);
    orderInfoFrame->setStyleSheet(
        "QFrame {"
        "    background-color: #f8f9fa;"
        "    border: 1px solid #e0e0e0;"
        "    border-radius: 8px;"
        "    padding: 12px;"
        "}"
    );

    QVBoxLayout* orderLayout = new QVBoxLayout(orderInfoFrame);
    orderLayout->setSpacing(6);

    // 获取站点名称
    QString fromName, toName;
    for (const auto& st : allData->stationsQueue) {
        if (st.getStationId() == oldOrderRef.getStartStationId()) fromName = QString::fromStdString(st.getName());
        if (st.getStationId() == oldOrderRef.getEndStationId()) toName = QString::fromStdString(st.getName());
    }

    QLabel* orderTitle = new QLabel("原订单信息", this);
    orderTitle->setFont(titleFont);
    orderTitle->setStyleSheet("color: #34495e;");
    orderLayout->addWidget(orderTitle);

    fromLabel = new QLabel("🚂 发站: " + fromName, this);
    toLabel = new QLabel("🎯 到站: " + toName, this);
    fromLabel->setStyleSheet("color: #555555; padding: 2px 0;");
    toLabel->setStyleSheet("color: #555555; padding: 2px 0;");

    orderLayout->addWidget(fromLabel);
    orderLayout->addWidget(toLabel);
    mainLayout->addWidget(orderInfoFrame);

    // === 改签选项卡片 ===
    QFrame* changeFrame = new QFrame(this);
    changeFrame->setFrameStyle(QFrame::StyledPanel);
    changeFrame->setStyleSheet(
        "QFrame {"
        "    background-color: white;"
        "    border: 1px solid #e0e0e0;"
        "    border-radius: 8px;"
        "    padding: 15px;"
        "}"
    );

    QVBoxLayout* changeLayout = new QVBoxLayout(changeFrame);
    changeLayout->setSpacing(15); // 增加间距

    infoLabel = new QLabel("请选择新的车次、日期和座位：", this);
    infoLabel->setFont(titleFont);
    infoLabel->setStyleSheet("color: #2c3e50;");
    changeLayout->addWidget(infoLabel);

    // 车次选择
    QVBoxLayout* trainLayout = new QVBoxLayout();
    trainLayout->setSpacing(6); // 增加标签和输入框之间的间距
    QLabel* trainLabel = new QLabel("选择车次:", this);
    trainLabel->setStyleSheet("color: #34495e; font-weight: bold;");
    trainCombo = new QComboBox(this);
    trainCombo->setMinimumHeight(38); // 增加输入框高度
    trainCombo->setStyleSheet(
        "QComboBox {"
        "    padding: 8px 12px;"
        "    border: 2px solid #e0e0e0;"
        "    border-radius: 6px;"
        "    background-color: white;"
        "    color: #2c3e50;"  // 确保文字颜色为深色
        "    selection-background-color: #3498db;"
        "    selection-color: white;"
        "}"
        "QComboBox:focus {"
        "    border-color: #3498db;"
        "}"
        "QComboBox::drop-down {"
        "    border: none;"
        "    width: 30px;"
        "}"
        "QComboBox::down-arrow {"
        "    image: none;"
        "    border-left: 5px solid transparent;"
        "    border-right: 5px solid transparent;"
        "    border-top: 5px solid #7f8c8d;"
        "}"
        "QComboBox QAbstractItemView {"
        "    background-color: white;"
        "    border: 1px solid #e0e0e0;"
        "    border-radius: 6px;"
        "    selection-background-color: #3498db;"
        "    selection-color: white;"
        "    outline: none;"
        "}"
        "QComboBox QAbstractItemView::item {"
        "    color: #2c3e50;"
        "    padding: 8px 12px;"
        "}"
        "QComboBox QAbstractItemView::item:hover {"
        "    background-color: #f0f0f0;"
        "}"
    );
    trainLayout->addWidget(trainLabel);
    trainLayout->addWidget(trainCombo);
    changeLayout->addLayout(trainLayout);

    // 日期选择
    QVBoxLayout* dateLayout = new QVBoxLayout();
    dateLayout->setSpacing(6);
    QLabel* dateLabel = new QLabel("选择日期:", this);
    dateLabel->setStyleSheet("color: #34495e; font-weight: bold;");
    dateEdit = new QDateEdit(this);
    dateEdit->setCalendarPopup(true);
    dateEdit->setMinimumHeight(38);
    QDate today = QDate::currentDate();
    dateEdit->setDate(today);
    dateEdit->setMinimumDate(today);
    dateEdit->setMaximumDate(today.addDays(31));
    dateEdit->setDisplayFormat("yyyy年MM月dd日");
    dateEdit->setStyleSheet(
        "QDateEdit {"
        "    padding: 8px 12px;"
        "    border: 2px solid #e0e0e0;"
        "    border-radius: 6px;"
        "    background-color: white;"
        "    color: #2c3e50;"  // 确保文字颜色为深色
        "    selection-background-color: #3498db;"
        "    selection-color: white;"
        "}"
        "QDateEdit:focus {"
        "    border-color: #3498db;"
        "}"
        "QDateEdit::drop-down {"
        "    border: none;"
        "    width: 30px;"
        "}"
    );

    // 美化日历控件
    QCalendarWidget* calendar = new QCalendarWidget(this);
    calendar->setStyleSheet(
        "QCalendarWidget {"
        "    background-color: white;"
        "    border: 1px solid #e0e0e0;"
        "    border-radius: 6px;"
        "}"
        "QCalendarWidget QToolButton {"
        "    color: #2c3e50;"
        "    font-weight: bold;"
        "    background-color: white;"
        "}"
        "QCalendarWidget QMenu {"
        "    background-color: white;"
        "    color: #2c3e50;"
        "}"
        "QCalendarWidget QAbstractItemView:enabled {"
        "    color: #2c3e50;"
        "    background-color: white;"
        "    selection-background-color: #3498db;"
        "    selection-color: white;"
        "}"
    );
    dateEdit->setCalendarWidget(calendar);

    dateLayout->addWidget(dateLabel);
    dateLayout->addWidget(dateEdit);
    changeLayout->addLayout(dateLayout);

    // 座位选择
    QVBoxLayout* seatLayout = new QVBoxLayout();
    seatLayout->setSpacing(6);
    QLabel* seatLabel = new QLabel("选择座位:", this);
    seatLabel->setStyleSheet("color: #34495e; font-weight: bold;");
    seatCombo = new QComboBox(this);
    seatCombo->setMinimumHeight(38);
    seatCombo->setStyleSheet(
        "QComboBox {"
        "    padding: 8px 12px;"
        "    border: 2px solid #e0e0e0;"
        "    border-radius: 6px;"
        "    background-color: white;"
        "    color: #2c3e50;"  // 确保文字颜色为深色
        "    selection-background-color: #3498db;"
        "    selection-color: white;"
        "}"
        "QComboBox:focus {"
        "    border-color: #3498db;"
        "}"
        "QComboBox::drop-down {"
        "    border: none;"
        "    width: 30px;"
        "}"
        "QComboBox::down-arrow {"
        "    image: none;"
        "    border-left: 5px solid transparent;"
        "    border-right: 5px solid transparent;"
        "    border-top: 5px solid #7f8c8d;"
        "}"
        "QComboBox QAbstractItemView {"
        "    background-color: white;"
        "    border: 1px solid #e0e0e0;"
        "    border-radius: 6px;"
        "    selection-background-color: #3498db;"
        "    selection-color: white;"
        "    outline: none;"
        "}"
        "QComboBox QAbstractItemView::item {"
        "    color: #2c3e50;"
        "    padding: 8px 12px;"
        "}"
        "QComboBox QAbstractItemView::item:hover {"
        "    background-color: #f0f0f0;"
        "}"
    );
    seatLayout->addWidget(seatLabel);
    seatLayout->addWidget(seatCombo);
    changeLayout->addLayout(seatLayout);

    mainLayout->addWidget(changeFrame);

    // === 票价显示 ===
    QFrame* priceFrame = new QFrame(this);
    priceFrame->setFrameStyle(QFrame::StyledPanel);
    priceFrame->setStyleSheet(
        "QFrame {"
        "    background-color: #e8f5e8;"
        "    border: 1px solid #c8e6c9;"
        "    border-radius: 8px;"
        "    padding: 15px;"  // 增加内边距
        "}"
    );

    QHBoxLayout* priceLayout = new QHBoxLayout(priceFrame);
    priceLabel = new QLabel("💰 票价: --", this);
    priceLabel->setFont(QFont("Microsoft YaHei", 12, QFont::Bold));
    priceLabel->setStyleSheet("color: #2e7d32;");
    priceLayout->addWidget(priceLabel);
    priceLayout->addStretch();
    mainLayout->addWidget(priceFrame);

    // === 按钮区域 ===
    QHBoxLayout* buttonLayout = new QHBoxLayout();
    buttonLayout->setSpacing(15);

    QPushButton* cancelBtn = new QPushButton("取消", this);
    cancelBtn->setMinimumSize(100, 40);
    cancelBtn->setStyleSheet(
        "QPushButton {"
        "    background-color: #95a5a6;"
        "    color: white;"
        "    border: none;"
        "    border-radius: 6px;"
        "    padding: 10px 20px;"
        "    font-weight: bold;"
        "}"
        "QPushButton:hover {"
        "    background-color: #7f8c8d;"
        "}"
        "QPushButton:pressed {"
        "    background-color: #95a5a6;"
        "}"
    );

    btnConfirm = new QPushButton("确认改签", this);
    btnConfirm->setMinimumSize(120, 40);
    btnConfirm->setStyleSheet(
        "QPushButton {"
        "    background-color: #3498db;"
        "    color: white;"
        "    border: none;"
        "    border-radius: 6px;"
        "    padding: 10px 20px;"
        "    font-weight: bold;"
        "}"
        "QPushButton:hover {"
        "    background-color: #2980b9;"
        "}"
        "QPushButton:pressed {"
        "    background-color: #3498db;"
        "}"
        "QPushButton:disabled {"
        "    background-color: #bdc3c7;"
        "    color: #7f8c8d;"
        "}"
    );

    buttonLayout->addStretch();
    buttonLayout->addWidget(cancelBtn);
    buttonLayout->addWidget(btnConfirm);
    mainLayout->addLayout(buttonLayout);

    // 初始化数据
    loadTrains();

    // 信号连接
    connect(trainCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ChangeTicketDialog::onTrainChanged);
    connect(dateEdit, &QDateEdit::dateChanged, this, &ChangeTicketDialog::onDateChanged);
    connect(seatCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ChangeTicketDialog::updatePriceLabel);
    connect(btnConfirm, &QPushButton::clicked, this, &ChangeTicketDialog::onConfirmClicked);
    connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);

    // 设置全局样式
    setStyleSheet(R"(
        QDialog {
            background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #f5f7fa, stop: 1 #e4e7ec);
            color: #333333;
        }
        QLabel {
            color: #555555;
        }
    )");
}

// 其他成员函数保持不变，但可以添加一些辅助功能
void ChangeTicketDialog::updatePriceLabel() {
    if (trainCombo->currentIndex() < 0 || seatCombo->currentIndex() < 0) {
        priceLabel->setText("💰 票价: --");
        // 禁用确认按钮
        btnConfirm->setEnabled(false);
        return;
    }

    int trainId = trainCombo->currentData().toInt();
    int seatId = seatCombo->currentData().toInt();
    std::string seatType;
    for (const auto& seat : allData->seatsQueue) {
        if (seat.getSeatId() == seatId && seat.getTrainId() == trainId) {
            seatType = seat.getSeatType();
            break;
        }
    }
    double price = AllData::CalculateTicketPrice(
        oldOrderRef.getStartStationId(), oldOrderRef.getEndStationId(), seatType, allData->stationsQueue);

    if (price < 0) {
        priceLabel->setText("💰 票价: --");
        btnConfirm->setEnabled(false);
    }
    else {
        priceLabel->setText(QString("💰 票价: %1 元").arg(QString::number(price, 'f', 2)));
        // 启用确认按钮
        btnConfirm->setEnabled(true);
    }
}

// 在loadSeats函数中添加按钮状态更新
void ChangeTicketDialog::loadSeats(int trainId, const std::string& date) {
    seatCombo->clear();
    if (!allData) {
        seatCombo->addItem("[数据未初始化]");
        btnConfirm->setEnabled(false);
        return;
    }

    bool found = false;
    for (const auto& seat : allData->seatsQueue) {
        if (seat.getTrainId() == trainId) {
            bool available = allData->IsSeatAvailable(date, trainId, seat.getSeatId(), oldOrderRef.getStartStationId(), oldOrderRef.getEndStationId());
            if (available) {
                // 添加座位信息，包含座位类型
                QString seatText = QString("%1 (%2)").arg(
                    QString::fromStdString(seat.getSeatNo()),
                    QString::fromStdString(seat.getSeatType())
                );
                seatCombo->addItem(seatText, seat.getSeatId());
                found = true;
            }
        }
    }

    // 默认选中原订单座位（如果可用），否则第一个可用座位
    int defaultSeatIdx = -1;
    for (int i = 0; i < seatCombo->count(); ++i) {
        if (seatCombo->itemData(i).toInt() == oldOrderRef.getSeatId()) {
            defaultSeatIdx = i;
            break;
        }
    }

    if (seatCombo->count() > 0) {
        if (defaultSeatIdx >= 0) {
            seatCombo->setCurrentIndex(defaultSeatIdx);
        }
        else {
            seatCombo->setCurrentIndex(0);
        }
        btnConfirm->setEnabled(true);
    }
    else {
        seatCombo->addItem("[无可用座位]");
        btnConfirm->setEnabled(false);
    }

    // 更新价格显示
    updatePriceLabel();
}



int ChangeTicketDialog::getNewTrainId() const { return newTrainId; }
int ChangeTicketDialog::getNewSeatId() const { return newSeatId; }
std::string ChangeTicketDialog::getNewDate() const { return newDate; }
bool ChangeTicketDialog::isSuccess() const { return success; }
